import { Component } from '@angular/core';
import { Student } from './model/student';
import { StudentService } from './service/student.service';
import { StudentVo } from './vo/student-vo';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = '我的查询页面';
  
  textvalue:string;
  numbervalue:number;

   student:Student;
   constructor(private studentservice:StudentService)
  {}
  studentvo:StudentVo;
  sl:Array<Student>;


  ngOnInit() {
  
    this.textvalue='这是我的angular';
    this.numbervalue=89;

     this.student=new Student();
     //this.student.name="皮皮虾";
    // this.student.sex="男";
    // this.student.birthday=new Date().getTime();
    this.studentservice.getAnObject().then((data:any)=>{this.student=data;})
    this.studentvo=new StudentVo();
    this.sl=new Array();
    this.loadStudentList();



}
add(){
  console.dir(this.studentvo);
  this.studentservice.addStudentInfo(this.studentvo)
  .then((data:any)=>{

    this.loadStudentList();
  })
  
  }

  loadStudentList(){
    this.studentservice.getStudentList()
    .then((data:any)=>{
     this.sl=data;
    })
  }
  getToUpdateStudent(id:string){

    this.studentservice.getSingleStudentById(id)
    .then((data:Student)=>{
    this.studentvo=new StudentVo();
    this.studentvo.studentid=data.studentid;
    this.studentvo.xh=data.stunum;
    this.studentvo.xm=data.name;
    
    })
    
    }
    delteStudent(id:string){

      this.studentservice.deleteStudent(id)
      .then((flag:boolean)=>{
      if(flag==true){
        this.loadStudentList();
      }
      else{
        alert("操作错误，请刷新后重试");
      }
      })
      }   








}
